using System.Collections.Generic;
using Common;
using CSC440TeamOne.CSC440BusinessService.Interface.Services;
using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.Unity.Utility;

namespace CSC440TeamOne.MyHealth
{
    /// <summary>
    /// Name - MyHealthController.cs
    /// Description - 
    /// Programmer - Matthew Mitchell
    /// Date coded - 11/27/2011
    /// Arguments - None
    /// Variables - None
    /// Files accessed by this code artifact - None
    /// Files changed by this code artifact - None
    /// I/O - None
    /// Error Handling - None
    /// Modifications -
    ///     1.0 - Initial coding
    /// Known Faults -
    ///     1.0 - None known
    /// </summary>
    public class MyHealthController : IMyHealthController
    {
        private IBusinessService _BusinessService;

        //private List<User> userList;
        //private List<Question> questionList;

        public MyHealthController([ServiceDependency] IBusinessService businessService)
        {
            Guard.ArgumentNotNull(businessService, "businessService");

            _BusinessService = businessService;

            //userList = new List<User>();
            //questionList = new List<Question>();
        }

        public void AddUser(User user)
        {
            _BusinessService.AddUser(user);

            //userList.Add(user);
        }

        public User FindUserById(string id)
        {
            //foreach (User user in userList)
            //{
            //    if (user.EmailAddress == id)
            //        return user;
            //}

            //return null;

            return _BusinessService.FindUserById(id);
        }

        public List<Question> LoadAllQuestions()
        {
            return _BusinessService.LoadAllQuestions();
        }

        public void SaveQuestionaireAnswer(int questionID, string answer)
        {
            //foreach (Question q in questionList)
            //{
            //    if (q.QuestionID == questionID)
            //    {
            //        q.AnswerText = answer;
            //        q.Answered = true;
            //        break;
            //    }
            //}

            _BusinessService.SaveQuestionaireAnswer(questionID, answer);
        }


        /// <summary>
        /// Loads the daily entry view for current user.
        /// </summary>
        /// <returns></returns>
        public DailyEntryViewModel LoadDailyEntryViewForCurrentUser()
        {
            return _BusinessService.LoadDailyEntryViewForCurrentUser();
        }

        /// <summary>
        /// Saves the daily entry view model.
        /// </summary>
        /// <param name="model">The model.</param>
        public void SaveDailyEntryViewModel(DailyEntryViewModel model)
        {
            _BusinessService.SaveDailyEntryViewModel(model);
        }

        /// <summary>
        /// Loads the health progress for current user.
        /// </summary>
        /// <returns></returns>
        public MyProgressViewModel LoadHealthProgressForCurrentUser()
        {
            return _BusinessService.LoadHealthProgressForCurrentUser();
        }

        /// <summary>
        /// Loads the health config for current user.
        /// </summary>
        /// <returns></returns>
        public MyHealthGoalConfigViewModel LoadHealthConfigForCurrentUser()
        {
            return _BusinessService.LoadUserHealthGoalsForCurrentUser();
        }

        /// <summary>
        /// Saves the health config.
        /// </summary>
        /// <param name="model">The model.</param>
        public void SaveHealthConfig(MyHealthGoalConfigViewModel model)
        {
            _BusinessService.SaveHealthConfig(model);
        }


        public SubmitRecipeModel getNewRecipeViewModel()
        {
            //throw new NotImplementedException();

            return _BusinessService.getNewRecipeViewModel();
        }

        public void parse(SubmitRecipeModel model)
        {

            //throw new NotImplementedException();

            _BusinessService.parse(model);
        }


        public ProcessRegistrationModel LoadProcessRegistrationModel()
        {
            //throw new NotImplementedException();

            return _BusinessService.LoadProcessRegistrationModel();
        }

        /// <summary>
        /// Loads the MyHealthSnapshotModel
        /// </summary>
        /// <returns></returns>
        public MyHealthSnapshotModel LoadMyHealthSnapshotModelForCurrentUser()
        {
            MyHealthSnapshotModel m = new MyHealthSnapshotModel();
            _BusinessService.LoadMyHealthSnapshotModel(m);
            return m;
        }

        #region IMyHealthController Members


        public User LoadCurrentUser()
        {
            return _BusinessService.LoadCurrentUser();
        }

        #endregion
    }
}
